package com.hangwei.paperless.view.window;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hangwei.paperless.MainSeeActivity;
import com.hangwei.paperless.R;
import com.hangwei.paperless.adapter.MainRepairAdapter;
import com.hangwei.paperless.model.bean.DRSInfo;
import com.hangwei.paperless.model.bean.MainRepairList;
import com.hangwei.paperless.model.bean.RecordListBean;
import com.hangwei.paperless.presenter.MainSeePresenter;
import com.hangwei.paperless.view.BaseView;
import com.twelve.all.net.CallBack;
import com.twelve.all.utils.LoadingDialog;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 张龙臣 on 2020/11/23.
 */

public abstract class BaseListView extends BaseView<MainSeeActivity, RecordListBean> {

    public BaseListView(MainSeeActivity activity) {
        super(activity);
    }

    private RecyclerView mRecyclerView;
    private MainRepairAdapter mAdapter;
    private boolean mDrsHasSaved = false;

    @Override
    protected View initView() {
        View inflate = LayoutInflater.from(mActivity).inflate(R.layout.page_see_base_main_repair, null);
        TextView tvTitle = (TextView) inflate.findViewById(R.id.tvTitle);
        tvTitle.setText(getTitle());
        mRecyclerView = inflate.findViewById(R.id.recyclerView);
        ImageView back = inflate.findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mActivity.finish();
            }
        });
        SwipeRefreshLayout refreshLayout = inflate.findViewById(R.id.refreshLayout);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        mAdapter = new MainRepairAdapter(null, 0) {
            @Override
            protected void onNaCurrent(String id) {

            }

            @Override

            protected void seal(final RecordListBean item, final int stampRole, final String resultVal) {
            }

            @Override
            protected void showBigPic(ArrayList<String> data, int position) {
                mActivity.showBigPic(data, position);
            }

            @Override
            protected void onSaveDRS(List<DRSInfo.DrsBean> drsList) {
            }
        };
        mAdapter.setEnableAll(false);
        mRecyclerView.setAdapter(mAdapter);
        final MainSeePresenter presenter = new MainSeePresenter(refreshLayout, mAdapter,mRecyclerView);
        presenter.setBillId(mActivity.getBillId());
        presenter.setPage(Integer.parseInt(getCurrentPage()));
        final LoadingDialog loadingDialog = new LoadingDialog(mActivity);
        loadingDialog.show();
        presenter.refresh(new CallBack<MainRepairList>() {
            @Override
            public void onCompleted(MainRepairList listBeans) {
                loadingDialog.dismiss();
            }

            @Override
            public void onError() {
                loadingDialog.dismiss();
            }
        });
        return inflate;
    }

    protected abstract String getTitle();

    protected abstract String getCurrentPage();

}
